@echo off
setlocal
set BASE=%~dp0
set PGDATA=%BASE%..\pgsql\data
set PGBIN=%BASE%..\pgsql\bin

if not exist "%PGDATA%\PG_VERSION" (
  "%PGBIN%\initdb" -D "%PGDATA%"
)
"%PGBIN%\pg_ctl" -D "%PGDATA%" -l "%PGDATA%\pg.log" start
"%PGBIN%\psql" -d postgres -c "CREATE DATABASE myapp;"
"%PGBIN%\psql" -d myapp -f "%BASE%..\pgsql\init.sql"